<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="迎着朝阳的博客" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    Centos7搭建hadoop spark集群之spark集群搭建 |  迎着朝阳
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="https://dxysun.com/static/yan.png" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  
<script>
var _hmt = _hmt || [];
(function() {
	var hm = document.createElement("script");
	hm.src = "https://hm.baidu.com/hm.js?aa994a8d65700b8835787dd39d079d7e";
	var s = document.getElementsByTagName("script")[0]; 
	s.parentNode.insertBefore(hm, s);
})();
</script>


</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-centosForSpark"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  Centos7搭建hadoop spark集群之spark集群搭建
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2018/04/16/centosForSpark/" class="article-date">
  <time datetime="2018-04-16T13:17:31.000Z" itemprop="datePublished">2018-04-16</time>
</a>   
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.4k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">6 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">JDK:1.8  </span><br><span class="line">Spark-2.2.0</span><br><span class="line">Hadoop Release:2.7.5  </span><br><span class="line">centos:7.3</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<p>两台主机</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">10.4.20.181 spark01</span><br><span class="line">10.4.20.48  spark02</span><br></pre></td></tr></table></figure>
<p>依赖环境Hadoop<br>参考我的另一篇博客<a href="https://dxysun.com/2018/04/16/centosForHadoop/">CentOs7搭建hadoop spark集群之hadoop集群搭建</a></p>
<h2 id="spark集群搭建"><a href="#spark集群搭建" class="headerlink" title="spark集群搭建"></a>spark集群搭建</h2><h3 id="下载spark2-2-0并解压到相应目录"><a href="#下载spark2-2-0并解压到相应目录" class="headerlink" title="下载spark2.2.0并解压到相应目录"></a>下载spark2.2.0并解压到相应目录</h3><p>我之前已经下好了spark2.2.0.tar.gz并用xftp上传到了主机spark01的/home/spark/download目录下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;home&#x2F;spark&#x2F;download</span><br><span class="line">tar -zxf spark-2.2.0-bin-hadoop2.7.tgz -C &#x2F;home&#x2F;spark&#x2F;app</span><br><span class="line">cd &#x2F;home&#x2F;spark&#x2F;app</span><br><span class="line">mv spark-2.2.0-bin-hadoop2.7 spark</span><br></pre></td></tr></table></figure>

<h3 id="设置环境变量"><a href="#设置环境变量" class="headerlink" title="设置环境变量"></a>设置环境变量</h3><p>如果是对所有的用户都生效就修改vi /etc/profile 文件<br>如果只针对当前用户生效就修改 vi ~/.bahsrc 文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim ~&#x2F;.bahsrc</span><br></pre></td></tr></table></figure>
<p>添加如下内容</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">#spark</span><br><span class="line">export SPARK_HOME&#x3D;&#x2F;home&#x2F;spark&#x2F;app&#x2F;spark&#x2F;</span><br><span class="line">export PATH&#x3D;$SPARK_HOME&#x2F;bin:$PATH</span><br></pre></td></tr></table></figure>
<blockquote>
<p>使环境变量生效，运行 source <del>/.bahsrc使</del>/.bahsrc文件生效，/etc/profile同理</p>
</blockquote>
<h3 id="修改配置"><a href="#修改配置" class="headerlink" title="修改配置"></a>修改配置</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;home&#x2F;spark&#x2F;app&#x2F;spark&#x2F;conf</span><br><span class="line">mv spark-env.sh.template spark-env.sh</span><br><span class="line">vim spark-env.sh</span><br></pre></td></tr></table></figure>
<p>在文件末尾添加如下内容</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">#Java安装目录</span><br><span class="line">export JAVA_HOME&#x3D;&#x2F;usr&#x2F;java</span><br><span class="line"></span><br><span class="line">#Spark主节点的IP</span><br><span class="line">export SPARK_MASTER_IP&#x3D;10.4.20.181</span><br><span class="line"></span><br><span class="line">#设置hadoop配置文件</span><br><span class="line">export HADOOP_CONF_DIR&#x3D;&#x2F;home&#x2F;spark&#x2F;app&#x2F;hadoop&#x2F;etc&#x2F;hadoop</span><br></pre></td></tr></table></figure>
<p>简单介绍几个变量</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">JAVA_HOME：Java安装目录</span><br><span class="line">SCALA_HOME：Scala安装目录</span><br><span class="line">HADOOP_HOME：hadoop安装目录</span><br><span class="line">HADOOP_CONF_DIR：hadoop集群的配置文件的目录</span><br><span class="line">SPARK_MASTER_IP：spark集群的Master节点的ip地址</span><br><span class="line">SPARK_WORKER_MEMORY：每个worker节点能够最大分配给exectors的内存大小</span><br><span class="line">SPARK_WORKER_CORES：每个worker节点所占有的CPU核数目</span><br><span class="line">SPARK_WORKER_INSTANCES：每台机器上开启的worker节点的数目</span><br></pre></td></tr></table></figure>
<p>修改 slaves</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;home&#x2F;spark&#x2F;app&#x2F;spark&#x2F;conf</span><br><span class="line">mv slaves.template slaves</span><br><span class="line">vim slaves</span><br></pre></td></tr></table></figure>
<p>删除localhost，添加如下内容</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">spark01</span><br><span class="line">spark02</span><br></pre></td></tr></table></figure>

<h3 id="配置集群"><a href="#配置集群" class="headerlink" title="配置集群"></a>配置集群</h3><p>复制节点<br>进去spark安装目录 ，打包，并发送，到其他节点</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd cd &#x2F;home&#x2F;spark&#x2F;app</span><br><span class="line">tar zcf spark.tar.gz spark</span><br><span class="line">scp spark.tar.gz spark@spark02:&#x2F;home&#x2F;spark&#x2F;app</span><br></pre></td></tr></table></figure>
<p>进去spark02节点 解压</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;home&#x2F;spark&#x2F;app</span><br><span class="line">tar -zxf spark.tar.gz</span><br></pre></td></tr></table></figure>
<p>设置环境变量，跟上面设置环境的步骤一样</p>
<p>到这里一步确保你的每一个节点下面环境变量都有</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">#jdk</span><br><span class="line">export JAVA_HOME&#x3D;&#x2F;usr&#x2F;java</span><br><span class="line">export JRE_HOME&#x3D;$JAVA_HOME&#x2F;jre</span><br><span class="line">export CLASSPATH&#x3D;.:$JAVA_HOME&#x2F;lib:$JRE_HOME&#x2F;lib</span><br><span class="line">export PATH&#x3D;$SPARK_HOME&#x2F;bin:$SCALA_HOME&#x2F;bin:$HADOOP_HOME&#x2F;bin:$JAVA_HOME&#x2F;bin:$PATH</span><br><span class="line"></span><br><span class="line">#hadoop</span><br><span class="line">export HADOOP_HOME&#x3D;&#x2F;home&#x2F;spark&#x2F;app&#x2F;hadoop&#x2F;</span><br><span class="line"></span><br><span class="line">#spark</span><br><span class="line">export SPARK_HOME&#x3D;&#x2F;home&#x2F;spark&#x2F;app&#x2F;spark&#x2F;</span><br></pre></td></tr></table></figure>
<p>你可以输入env查看环境变量</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">env</span><br></pre></td></tr></table></figure>

<h3 id="启动集群"><a href="#启动集群" class="headerlink" title="启动集群"></a>启动集群</h3><p>关闭防火墙</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl stop firewalld.service</span><br></pre></td></tr></table></figure>
<p>启动 Hadoop</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">start-dfs.sh</span><br><span class="line">start-yarn.sh</span><br><span class="line">mr-jobhistory-daemon.sh start historyserver</span><br></pre></td></tr></table></figure>
<blockquote>
<p>此时hadoop的环境变量已配好</p>
</blockquote>
<p>启动 Spark</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;home&#x2F;spark&#x2F;app&#x2F;spark</span><br><span class="line">.&#x2F;sbin&#x2F;start-all.sh</span><br></pre></td></tr></table></figure>
<p>启动 Spark Shell</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;home&#x2F;spark&#x2F;app&#x2F;spark</span><br><span class="line">.&#x2F;bin&#x2F;spark-shell</span><br></pre></td></tr></table></figure>
<p>spark web界面访问：<a href="http://10.4.20.181:8080" target="_blank" rel="noopener">http://10.4.20.181:8080</a><br><img src="http://qiniu.dxysun.com/18-4-16/25982754.jpg" alt="spark web界面"><br>spark-shell 界面访问：<a href="http://10.4.20.181:4040" target="_blank" rel="noopener">http://10.4.20.181:4040</a><br><img src="http://qiniu.dxysun.com/18-4-16/59022269.jpg" alt="spark-shell界面"></p>
<p>使用jps命令看到有以下几个进程<br><img src="http://qiniu.dxysun.com/18-4-16/14370965.jpg" alt=""><br>spark和hadoop集群搭建成功</p>
<h2 id="集群运行模式"><a href="#集群运行模式" class="headerlink" title="集群运行模式"></a>集群运行模式</h2><p>Spark应用程序在集群中运行时，需要借助于集群管理器（包括本地集群管理器、YARN、Mesos）来为其实现资源管理调度服务，实现对集群中各个机器的访问这里通过简单的示例介绍其中两种：独立集群管理器和Hadoop Yarn集群管理器。通过介绍，我们可以了解到如何在这两种集群管理器上运行Spark应用程序。</p>
<h3 id="独立集群管理器"><a href="#独立集群管理器" class="headerlink" title="独立集群管理器"></a>独立集群管理器</h3><p>（1）在集群中运行应用程序JAR包<br>向独立集群管理器提交应用，需要把spark：//spark01:7077作为主节点参数递给spark-submit。<br>下面我们可以运行Spark安装好以后自带的样例程序SparkPi，它的功能是计算得到pi的值（3.1415926）。<br>在Shell中输入如下命令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bin&#x2F;spark-submit --class org.apache.spark.examples.SparkPi --master spark:&#x2F;&#x2F;spark01:7077 examples&#x2F;jars&#x2F;spark-examples_2.11-2.2.0.jar 100 2&gt;&amp;1 | grep &quot;Pi is roughly&quot;</span><br></pre></td></tr></table></figure>
<p>运行结果如下<br><img src="http://qiniu.dxysun.com/18-4-16/1836194.jpg" alt="运行结果"></p>
<p>运行自己上传的jar包</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bin&#x2F;spark-submit --class WordCount &#x2F;home&#x2F;spark&#x2F;app&#x2F;spark&#x2F;mycode&#x2F;jars&#x2F;WordCount.jar</span><br></pre></td></tr></table></figure>
<blockquote>
<p>–class后面跟的是要运行的jar包中的主类名</p>
</blockquote>
<p>（2）在集群中运行spark-shell<br>也可以用spark-shell连接到独立集群管理器上。<br>首先做一点准备工作，把一个README.md文件拷贝到HDFS上，用于后面的测试。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;home&#x2F;saprk&#x2F;app&#x2F;spark&#x2F;</span><br><span class="line"># 下面这条命令中，我们把spark安装目录下的README.md文件上传到分布式文件系统HDFS的根目录下</span><br><span class="line">hadoop fs -put README.md &#x2F;</span><br></pre></td></tr></table></figure>
<p>在Shell中输入如下命令启动进入spark-shell：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;home&#x2F;saprk&#x2F;app&#x2F;spark&#x2F;</span><br><span class="line">bin&#x2F;spark-shell --master spark:&#x2F;&#x2F;spark01:7077</span><br></pre></td></tr></table></figure>
<p>可以在spark-shell中输入如下代码进行测试：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">scala&gt; val textFile &#x3D; sc.textFile(&quot;hdfs:&#x2F;&#x2F;spark01:9000&#x2F;README.md&quot;)</span><br><span class="line">textFile: org.apache.spark.rdd.RDD[String] &#x3D; hdfs:&#x2F;&#x2F;spark01:9000&#x2F;README.md MapPartitionsRDD[1] at textFile at &lt;console&gt;:24</span><br><span class="line">scala&gt; textFile.count()</span><br><span class="line">res0: Long &#x3D; 99                                                                 </span><br><span class="line">scala&gt; textFile.first()</span><br><span class="line">res1: String &#x3D; # Apache Spark</span><br></pre></td></tr></table></figure>

<p>用户在独立集群管理Web界面查看应用的运行情况，可以浏览器中输入地址进行查看(<a href="http://spark01:8080/)，如下图：" target="_blank" rel="noopener">http://spark01:8080/)，如下图：</a><br><img src="http://qiniu.dxysun.com/18-4-16/88502044.jpg" alt=""></p>
<h3 id="Hadoop-YARN管理器"><a href="#Hadoop-YARN管理器" class="headerlink" title="Hadoop YARN管理器"></a>Hadoop YARN管理器</h3><p>在集群中运行应用程序JAR包<br>向Hadoop YARN集群管理器提交应用，需要把yarn-cluster作为主节点参数递给spark-submit。<br>在Shell中输入如下命令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bin&#x2F;spark-submit --class org.apache.spark.examples.SparkPi --master yarn-cluster examples&#x2F;jars&#x2F;spark-examples_2.11-2.2.0.jar</span><br></pre></td></tr></table></figure>
<p>运行后，根据在Shell中得到输出的结果地址查看，如下图：<br><img src="http://qiniu.dxysun.com/18-4-16/32163661.jpg" alt=""><br>复制结果地址到浏览器，点击查看Logs，再点击stdout，即可查看结果，如下图：<br><img src="http://qiniu.dxysun.com/18-4-16/49358342.jpg" alt=""><br><img src="http://qiniu.dxysun.com/18-4-16/80911383.jpg" alt=""><br><img src="http://qiniu.dxysun.com/18-4-16/88338755.jpg" alt=""></p>
<h2 id="关闭集群"><a href="#关闭集群" class="headerlink" title="关闭集群"></a>关闭集群</h2><p>关闭hadoop</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">stop-dfs.sh</span><br><span class="line">stop-yarn.sh</span><br><span class="line">mr-jobhistory-daemon.sh stop historyserver</span><br></pre></td></tr></table></figure>
<p>关闭spark</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;home&#x2F;spark&#x2F;app&#x2F;spark</span><br><span class="line">.&#x2F;sbin&#x2F;stop-all.sh</span><br></pre></td></tr></table></figure>

 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://dxysun.com/2018/04/16/centosForSpark/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/centos/" rel="tag">centos</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/" rel="tag">linux</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/spark/" rel="tag">spark</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2018/04/19/springForHotPublish/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            SpringBoot配置devtools实现热部署
          
        </div>
      </a>
    
    
      <a href="/2018/04/16/centosForHadoop/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Centos7搭建hadoop spark集群之hadoop集群搭建</div>
      </a>
    
  </nav>

  
   
  
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2024
        <i class="ri-heart-fill heart_icon"></i> dxysun
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
        <li>
          <a href="https://beian.miit.gov.cn" target="_black" rel="nofollow">豫ICP备17012675号-1</a>
        </li>
        
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="https://dxysun.com/static/logo.png" alt="迎着朝阳"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/photos">相册</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="https://tu.dxysun.com/alipay-20201219151322.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="https://tu.dxysun.com/weixin-20201219151346.png">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


<script src="/js/dz.js"></script>



    
  </div>
</body>

</html>